home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Src / MTAconsole / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  6.0 KB  |  278 lines

  1. /* misc.c : routines that wouldn't fit anywhere else */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Src/MTAconsole/RCS/misc.c,v 6.0 1991/12/18 20:26:48 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Src/MTAconsole/RCS/misc.c,v 6.0 1991/12/18 20:26:48 jpo Rel $
  9.  *
  10.  * $Log: misc.c,v $
  11.  * Revision 6.0  1991/12/18  20:26:48  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include    "console.h"
  19. #include    <X11/cursorfont.h>
  20.  
  21. #include "back.bit"
  22. Pixmap    backpixmap;
  23.  
  24. struct color_item     *colors = NULL;
  25. XColor        white,
  26.         exact_white,
  27.         black,
  28.         exact_black;
  29. Pixel        fg,
  30.         bg;
  31. extern int    compat;
  32.  
  33. create_pixmaps(disp)
  34. Display    *disp;
  35. {
  36.     Window    root;
  37.     root = XDefaultRootWindow(disp);
  38.     backpixmap = XCreatePixmapFromBitmapData(disp, root,
  39.                        back_bits, back_width, back_height,
  40.                        fg,
  41.                        bg, 
  42.                        XDefaultDepth(disp,XDefaultScreen(disp)));
  43. }
  44.  
  45. static Colormap    color_map;
  46.  
  47. extern int    num_colors;
  48. extern Widget    quit_command;
  49.  
  50. #define MAX_COLOR_VALUE 65535
  51.  
  52. /* setup the colours used */
  53. /* ARGSUSED */
  54. SetColours(disp, win)
  55. Display    *disp;
  56. Window    win;
  57. {
  58.     int    i,
  59.         badness;
  60.     Colormap    cmap2;
  61.     double    fract;
  62.  
  63.     XtVaGetValues (quit_command,
  64.            XtNbackground, &bg,
  65.            XtNforeground, &fg,
  66.            NULL);
  67.  
  68.     color_map = DefaultColormap(disp,
  69.                      XDefaultScreen(disp));
  70.  
  71.     XAllocNamedColor(disp, color_map,
  72.              "white",
  73.              &white,
  74.              &exact_white);
  75.     
  76.     XAllocNamedColor(disp, color_map,
  77.              "black",
  78.              &black,
  79.              &exact_black);
  80.  
  81.     colors = (struct color_item *) calloc((unsigned) num_colors,
  82.                            sizeof(struct color_item));
  83.     if (num_colors == 1) {
  84.         colors[0].badness = 0;
  85.         colors[0].colour.pixel = fg;
  86.     } else {
  87.         for (i = 0; i < num_colors; i++) {
  88.             badness = (i * max_bad_channel/num_colors);
  89.             colors[i].badness = badness;
  90.  
  91.             colors[i].colour.pixel = 0;
  92.             colors[i].colour.blue = 0;
  93.  
  94.             if (badness > max_bad_channel/2)
  95.                 colors[i].colour.red = MAX_COLOR_VALUE;
  96.             else {
  97.                 fract = (double) badness * 2.0 / (double) max_bad_channel;
  98.                 colors[i].colour.red = fract * MAX_COLOR_VALUE;
  99.             }
  100.             if (colors[i].colour.red > MAX_COLOR_VALUE)
  101.                 colors[i].colour.red = MAX_COLOR_VALUE;
  102.  
  103.             if (max_bad_channel - badness > max_bad_channel/2)
  104.                 colors[i].colour.green = MAX_COLOR_VALUE;
  105.             else {
  106.                 fract = ((double) (max_bad_channel - badness) * 2.0) / (double) max_bad_channel;
  107.                 colors[i].colour.green = fract * MAX_COLOR_VALUE;
  108.             }
  109.             if (colors[i].colour.green > MAX_COLOR_VALUE)
  110.                 colors[i].colour.green = MAX_COLOR_VALUE;
  111.  
  112.             colors[i].colour.flags = DoRed | DoGreen | DoBlue;
  113.         }
  114.         for (i = 0; i < num_colors; i++) {
  115.             if (XAllocColor(disp, color_map, &(colors[i].colour)) == 0) {
  116.                 cmap2 = XCopyColormapAndFree(disp, color_map);
  117.                 for (; i < num_colors; i++) 
  118.                     XAllocColor(disp, 
  119.                             cmap2, 
  120.                             &(colors[i].colour));
  121.                 color_map = cmap2;
  122.                 break;
  123.             }
  124.         }
  125.         XSetWindowColormap(disp, win, color_map);
  126.     }
  127.     create_pixmaps(disp);
  128. }
  129.  
  130. char    *stripstr(str)
  131. char    *str;
  132. {    
  133.     char    *ret,
  134.         *ix;
  135.  
  136.     ix = str;
  137.     while (*ix != '\0' && isspace(*ix)) ix++;
  138.     ret = ix;
  139.     while(*ix != '\0' && *ix != '\n') ix++;
  140.     if (*ix == '\n') *ix = '\0';
  141.  
  142.     return ret;
  143. }
  144.  
  145. int is_loc_chan(chan)
  146. struct chan_struct    *chan;
  147. {
  148.     if (chan->chantype == int_Qmgr_chantype_mts
  149.         && chan->outbound > 0)
  150.         return    TRUE;
  151.     else
  152.         return FALSE;
  153. }
  154.  
  155. extern Display    *disp;
  156. extern Widget    top;
  157. Window        waitWindow = NULL;
  158.  
  159. StartWait()
  160. {
  161.     if (waitWindow == (Window)NULL) {
  162.         XSetWindowAttributes    attributes;
  163.         attributes.cursor = XCreateFontCursor(disp, XC_watch);
  164.         attributes.do_not_propagate_mask = (KeyPressMask | 
  165.                             KeyReleaseMask |
  166.                             ButtonPressMask | 
  167.                             ButtonReleaseMask |
  168.                             PointerMotionMask);
  169.         waitWindow = XCreateWindow(disp,
  170.                        XtWindow(top),
  171.                        0, 0,
  172.                        XDisplayWidth(disp,
  173.                              XDefaultScreen(disp)),
  174.                        XDisplayHeight(disp,
  175.                               XDefaultScreen(disp)),
  176.                        (unsigned int) 0,
  177.                        CopyFromParent,
  178.                        InputOnly,
  179.                        CopyFromParent,
  180.                        (CWDontPropagate | CWCursor),
  181.                        &attributes);
  182.     }
  183.     (void) XMapRaised(disp, waitWindow);
  184.     (void) XFlush(disp);
  185. }
  186.  
  187. EndWait()
  188. {
  189.     (void) XUnmapWindow(disp, waitWindow);
  190. }
  191.  
  192. extern Widget    time_label;
  193. extern Widget    statistics;
  194.  
  195. undisplay_time_label()
  196. {
  197.   XtSetMappedWhenManaged(time_label, False);
  198.   if (statistics != NULL)
  199.       XtSetMappedWhenManaged(statistics, False);
  200. }
  201.  
  202. extern Widget compat_stat_pane;
  203.  
  204. redo_statistics_compat()
  205. {
  206.     if (statistics != NULL) {
  207.         if (compat) {
  208.             XtSetMappedWhenManaged(compat_stat_pane, False);
  209.             XtSetMappedWhenManaged(statistics, False);
  210.         } else {
  211.             XtSetMappedWhenManaged(statistics, True);
  212.             XtSetMappedWhenManaged(compat_stat_pane, True);
  213.         }
  214.     }
  215. }
  216.  
  217. display_time_label()
  218. {
  219.   update_time_label();
  220.   XtSetMappedWhenManaged(time_label, True);
  221.   if (!compat && statistics != NULL)
  222.       XtSetMappedWhenManaged(statistics, True);
  223. }
  224.  
  225. extern time_t currentTime;
  226. extern char   *time_t2RFC();
  227. extern int    currChans, maxChans;
  228. extern int    messagesIn, messagesOut, addrIn, addrOut;
  229. extern time_t    boottime;
  230.  
  231. update_time_label()
  232. {
  233.   char    *str, buf[BUFSIZ];
  234.   time(¤tTime);
  235.   str = time_t2RFC(currentTime);
  236.   (void) sprintf(buf, "%d channel%s running (max %d) at %s", 
  237.          currChans, (currChans == 1) ? "" : "s",
  238.          maxChans, str);
  239.   free(str);
  240.   XtVaSetValues(time_label, 
  241.         XtNlabel, buf,
  242.         NULL);
  243.   
  244.   if (!compat && statistics != NULL) {
  245. #define    NUMBUF    15
  246.       char    adIn[NUMBUF], mgIn[NUMBUF], adOut[NUMBUF], mgOut[NUMBUF];
  247.       str = time_t2RFC(boottime);
  248.       num2unit(addrIn, adIn);
  249.       num2unit(messagesIn, mgIn);
  250.       num2unit(addrOut, adOut);
  251.       num2unit(messagesOut, mgOut);
  252.       (void) sprintf(buf, "running since %s\nInbound %s Message%s to %s Recipient%s\nOutbound %s Message%s to %s Recipient%s",
  253.              str, mgIn, (messagesIn != 1) ? "s" : "",
  254.              adIn, (addrIn != 1) ? "s" : "",
  255.              mgOut, (messagesOut != 1) ? "s" : "",
  256.              adOut, (addrOut != 1) ? "s" : "");
  257.       free(str);
  258.       XtVaSetValues(statistics,
  259.             XtNlabel, buf,
  260.             NULL);
  261.   }
  262. }
  263.  
  264. extern State    connectState;
  265.  
  266. /* ARGSUSED */        
  267. void setLoad (w, ptr_load, load)
  268. Widget        w;
  269. double        *ptr_load;
  270. double        *load;
  271. {
  272.     if (connectState == connected)
  273.         *load = *ptr_load / 100;
  274.     else
  275.         *load = 0;
  276. }
  277.     
  278.